//
//  MenuTestController.m
//  FastRunDemo
//
//  Created by 苟亚明 on 16/9/18.
//  Copyright © 2016年 苟亚明. All rights reserved.
//

#import "MenuTestController.h"
#import <MJRefresh.h>
#import "qiangDanCell.h"
#import "robListCell.h"
@interface MenuTestController ()

@end

@implementation MenuTestController

static NSString *qiangDanCellID = @"social";
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 刷新控件
    [self setupRefresh];
    
    // 初始化tableView
    [self setupTableView];
}
/**
 * 初始化tableView
 */
- (void)setupTableView{
    [self.tableView registerNib:[UINib nibWithNibName:@"robListCell" bundle:nil] forCellReuseIdentifier:qiangDanCellID];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 230;
    self.tableView.backgroundColor = [UIColor colorWithRed:224/255.0 green:224/255.0 blue:224/255.0 alpha:1];
    self.tableView.backgroundColor = [UIColor whiteColor];
    
}
/**
 * 设置刷新控件
 */
- (void)setupRefresh{
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    self.tableView.mj_header.automaticallyChangeAlpha = YES;
    [self.tableView.mj_header beginRefreshing];
    
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
}

- (void)loadNewData{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
    });
}

- (void)loadMoreData{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
        [self.tableView.mj_footer endRefreshing];
    });
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    int x = arc4random() % 100;
    robListCell *cell = [tableView dequeueReusableCellWithIdentifier:qiangDanCellID];

    return cell;
}

@end
